<?php
/**
*定义创建数据类型的事件
**/
namespace Fang\AlysmsBundle\Event;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Fang\AlysmsBundle\Entity\SmsType;

class AlySmsTypeEvent extends Event
{
	const NAME="alysms.type";//定义事件名称

	private $smstypes;//短信类型列表

	public function __construct()
	{
		$this->smstypes = [];
	}
	/**
	*获取短信类型
	**/
	public function getTypes()
	{
		return $this->smstypes;
	}
	/**
	*设置短信类型
	*@param $validator 使用注入方式，验证器
	**/
	public function setType(SmsType $smstype, ValidatorInterface $validator)
	{
		$errors = $validator->validate();
		if(count($errors) > 0)
			return false;

		$this->smstypes[$smstype->getSmstype()] = $smstype;
		return true;
	}
}